//
//  HMFirstView.swift
//  swift微博项目
//
//  Created by huodian on 16/9/23.
//  Copyright © 2016年 huodian. All rights reserved.
//

import UIKit

protocol HMFirstViewDelegete:NSObjectProtocol {
    
    

    func clickLoadBtn()
    
    
    func clickRigestBtn()
    
    
    
}


class HMFirstView: UIView {

    
    weak var delegate : HMFirstViewDelegete?
    
   
    func loadUnsameview(detail:String,imageNamed:String? = nil){
        
        if imageNamed == nil {
            
           animatedTheCircleview()
            
        }else
        {
            circleView.image =  UIImage(named: imageNamed!)
            
            roomView.isHidden = true
            
            backView.isHidden = true
            
            detailLable.text = detail
            
          
            
        }
        
    }
    
  
    func animatedTheCircleview() {
        
        let basic = CABasicAnimation(keyPath:"transform.rotation")

        basic.repeatCount = MAXFLOAT
        
        basic.toValue = M_PI * 2
        
        basic.duration = 10
        
        basic.isRemovedOnCompletion = false
        
        circleView.layer.add(basic, forKey: nil)
        
        
    }
    
   
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setMyUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setMyUI() {
        
        
        self.addSubview(circleView)
        
         self.addSubview(backView)
        
        self.addSubview(roomView)
        
       
        
        self.addSubview(detailLable)
        
        self.addSubview(rightBtn)
        
        self.addSubview(leftBtn)
        
          bringSubview(toFront: roomView)
        
        
        circleView.snp.makeConstraints({ (make) in
        
            make.centerX.equalTo(self)
            
            make.centerY.equalTo(self.snp.centerY).offset(-80)
         
        })
        
        roomView.snp.makeConstraints { (make) in
            
            make.center.equalTo(circleView)
            
        }
        
        backView.snp.makeConstraints { (make) in
            
            make.center.equalTo(circleView.snp.center)
        }
        
        detailLable.snp.makeConstraints { (make) in
            
            make.top.equalTo(circleView.snp.bottom).offset(10)
            
            make.centerX.equalTo(circleView.snp.centerX)
        }
        
        leftBtn.snp.makeConstraints { (make) in
            make.top.equalTo(detailLable.snp.bottom).offset(10)
            
            make.leading.equalTo(detailLable.snp.leading)
            
            make.width.equalTo(100)
        }
        
        rightBtn.snp.makeConstraints { (make) in
            make.top.equalTo(detailLable.snp.bottom).offset(10)
            
            make.trailing.equalTo(detailLable.snp.trailing)
            
            make.width.equalTo(100)
        }
        
        
        leftBtn.addTarget(self, action: #selector(clickleftBtn), for: UIControlEvents.touchUpInside)
        
        rightBtn.addTarget(self, action: #selector(clickrightBtn), for: UIControlEvents.touchUpInside)
    }
    
    func clickrightBtn() {
        
        
        delegate?.clickRigestBtn()
    }
    
    func clickleftBtn() {
        
        delegate?.clickLoadBtn()
    }
    
    
    lazy var circleView:UIImageView = UIImageView(image: #imageLiteral(resourceName: "visitordiscover_feed_image_smallicon"))
    
    lazy var roomView:UIImageView = UIImageView(image:#imageLiteral(resourceName: "visitordiscover_feed_image_house"))
    
    lazy var backView:UIImageView = UIImageView(image:#imageLiteral(resourceName: "visitordiscover_feed_mask_smallicon"))
    
    lazy var detailLable : UILabel = {
        
        let label1 = UILabel(title: "哈哈哈哈哈哈哈哈哈哈哈哈呀呀呀呀呀呀呀呀呀", font: 14, corlor: UIColor.darkGray)
        
        label1.preferredMaxLayoutWidth = 226
        
        label1.textAlignment = NSTextAlignment.center
        
        return label1
        
    }()
    
    lazy var leftBtn : UIButton = {
        
       let btn = UIButton(title: "注册", titleColor: UIColor.darkGray, font: 14)
        
        btn.setBackgroundImage(UIImage(named: "common_button_white"), for: UIControlState.normal)
        
        return btn
    
        
    }()
    lazy var rightBtn : UIButton = {
        
        let btn = UIButton(title: "登陆", titleColor: UIColor.orange, font: 14)
        
        btn.setBackgroundImage(UIImage(named: "common_button_white"), for: UIControlState.normal)
        
        return btn
        
        
    }()
    
}
